/**
 * 
 */
package cc.rico.redis.utils;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;

/**
 * redis sharded 工具
 * @author rico 2016年7月6日
 *
 */
public class ShardedJedisUtil {
	private static final Logger logger = LoggerFactory.getLogger(ShardedJedisUtil.class);
	// redis host
	private static final String host = "192.168.223.143";
	
	private static ShardedJedis shardedJedis;
	static {
		logger.info("ShardedJedisUtil init shardedJedis success...");
		
		JedisShardInfo si1 = new JedisShardInfo(host, 6379);
		JedisShardInfo si2 = new JedisShardInfo(host, 6380);
		
	    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();  
	    shards.add(si1);  
	    shards.add(si2);
	    
	    shardedJedis = new ShardedJedis(shards);
	}
	
	private ShardedJedisUtil() {
		
	}
	
	public static ShardedJedis getInstance() {
		return shardedJedis;
	}
	
	public static void close(ShardedJedis shardedJedis) {
		shardedJedis.close();
	}
	
}
